package 笔试;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class 史莱姆队列 {
    public static void main(String[] args) {
        HashMap<Character, Integer> mp = new HashMap<>();
        Scanner scan = new Scanner(System.in);
        int T = scan.nextInt();
        Queue<Character> q = new LinkedList<>();
        int ans = 0;
        while (T-- > 0) {
            int x = scan.nextInt();
            if(x == 1) {
                String s = scan.nextLine();
                char[] arr = s.toCharArray();
                char c = arr[0];
                q.offer(c);
                if(mp.get(c) == 0) {
                    ans++;
                }
                mp.put(c, mp.getOrDefault(c, 0)+1);
            }else if(x == 2) {
                char c = q.poll();
                mp.put(c, mp.getOrDefault(c, 0)-1);
                if(mp.get(c) == 0) {
                    ans--;
                }
            } else {
                System.out.println(ans);
            }
        }
    }
}











